package com.cloudcc.mobile.parser;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

import com.cloudcc.mobile.entity.MyChatter;
import com.cloudcc.mobile.entity.MyChatterMessage;
import com.cloudcc.mobile.util.Json;
import com.cloudcc.mobile.util.Tools;

public class MyChatterParser {
	/**
	 * 解析我所追随的内容
	 * */
	public static MyChatterMessage getMyChatter(String jsonString) {
		ArrayList<MyChatter> list = new ArrayList<MyChatter>();
		MyChatterMessage msg = new MyChatterMessage();
		try {
			JSONObject obj = new JSONObject(jsonString);
			msg.setResult(obj.getBoolean("result"));
			msg.setReturnInfo(obj.getString("returnInfo"));
			msg.setReturnCode(obj.getString("returnCode"));
			JSONArray json = obj.getJSONArray("data");
			for (int i = 0; i < json.length(); i++) {
				JSONObject jsonObj = json.getJSONObject(i);
				MyChatter myChatter = (MyChatter) Json.toObject(
						jsonObj.toString(), MyChatter.class);
				list.add(myChatter);
			}
			msg.setList(list);

		} catch (Exception e) {
			Tools.handle(e);
		}
		return msg;
	}

}
